﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Libraries.Common;
using Libraries.Entities;

namespace Libraries.Repositories
{
    public class StatusAccountRepository
    {
        private static StatusAccount ParseToEntityStatusAccount(IDataRecord dataReader)
        {
            if (dataReader != null)
            {
                return new StatusAccount
                {
                    StatusAccountId = dataReader["StatusAccountId"].ToInt32OrDefault(),
                    StatusAccountName = dataReader["Status"].ToStringOrDefault(),
                    Descriptions = dataReader["Descriptions"].ToStringOrDefault()
                };
            }
            return null;
        }

        public Collection<StatusAccount> ListAllStatusAccount()
        {
            Collection<StatusAccount> list = null;
            if (!string.IsNullOrEmpty(ProcedureConfiguration.ListAllStatusAccount))
            {
                using (var result = RepositorySql.SqlHelper.ExecuteReader(ProcedureConfiguration.ListAllStatusAccount, ConnectionConfiguration.ConnectionString))
                {
                    if (result != null)
                    {
                        list = new Collection<StatusAccount>();
                        while (result.Read())
                        {
                            list.Add(ParseToEntityStatusAccount(result));
                        }
                    }
                }
            }
            return list;
        }
    }
}
